package pl.PawelAndAlicja.badugiproject.main.Cards;

public class ClientDeck {

    public ClientDeck(FlyweightFactoryCard factoryCard) {
        this.flyweightFactoryCard = factoryCard;
    }

    public FlyweightCard createCard(String cardType, String cardName) {

        if (cardType.equals("Spade")) {
            FlyweightSpadeCard flyweightCard;
            flyweightCard = flyweightFactoryCard.getCard(new FlyweightSpadeCard(cardName));
            return flyweightCard;
        } else if (cardType.equals("Club")) {
            FlyweightClubCard flyweightCard;
            flyweightCard = flyweightFactoryCard.getCard(new FlyweightClubCard(cardName) );
            return flyweightCard;
        } else if (cardType.equals("Diamond")) {
            FlyweightDiamondCard flyweightCard;
            flyweightCard = flyweightFactoryCard.getCard(new FlyweightDiamondCard(cardName) );
            return flyweightCard;
        } else if (cardType.equals("Heart")) {
            FlyweightHeartCard flyweightCard;
            flyweightCard = flyweightFactoryCard.getCard(new FlyweightHeartCard(cardName) );
            return flyweightCard;
        }
        return null;
    }

    FlyweightCard createCard(String cardType, int power) {
        if (cardType.equals("Spade")) {
            FlyweightSpadeCard flyweightCard;
            flyweightCard = flyweightFactoryCard.getCard(new FlyweightSpadeCard(power));
            return flyweightCard;
        } else if (cardType.equals("Club")) {
            FlyweightClubCard flyweightCard;
            flyweightCard = flyweightFactoryCard.getCard(new FlyweightClubCard(power) );
            return flyweightCard;
        } else if (cardType.equals("Diamond")) {
            FlyweightDiamondCard flyweightCard;
            flyweightCard = flyweightFactoryCard.getCard(new FlyweightDiamondCard(power) );
            return flyweightCard;
        } else if (cardType.equals("Heart")) {
            FlyweightHeartCard flyweightCard;
            flyweightCard = flyweightFactoryCard.getCard(new FlyweightHeartCard(power) );
            return flyweightCard;
        }
        return null;
    }

//    FlyweightCard getCard(String cardType, String cardName) {
//
//    }

    public ClientDeck createDeck() {
        ClientDeck clientDeck = new ClientDeck(this.flyweightFactoryCard);

        createColorDeck(clientDeck, "Spade");
        createColorDeck(clientDeck, "Club");
        createColorDeck(clientDeck, "Diamond");
        createColorDeck(clientDeck, "Heart");

        return clientDeck;
    }

    public void showDeck(){
        flyweightFactoryCard.showArrayCards();
    }

    public void shuffleDeck(){
        flyweightFactoryCard.shuffleDeck("Spade");
        flyweightFactoryCard.shuffleDeck("Club");
        flyweightFactoryCard.shuffleDeck("Diamond");
        flyweightFactoryCard.shuffleDeck("Heart");
    }

    public void removeCard(String typeCard, String nameCard) {
        flyweightFactoryCard.removeCard(typeCard, nameCard);
    }

    public boolean isHiddenCard(FlyweightCard card) {
        return card.isHidden();
    }

    public int size() {
       return flyweightFactoryCard.sizeCardsFactory();
    }

    private void createColorDeck(ClientDeck clientDeck, String colorType) {
        for (int i = 1; i < 14; i++) {
            clientDeck.createCard(colorType, i);
        }
    }

    public FlyweightFactoryCard getFlyweightFactoryCard() {
        return flyweightFactoryCard;
    }

    private final FlyweightFactoryCard flyweightFactoryCard;
}
